home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / full / nt / MSSql / I386 / sqlx86.exe / PTK / SAMPLES / OLEAUTO / LOOPBACK.DAO / CSQLDAO.CLS next >
Encoding:
Text File  |  1996-04-03  |  1.6 KB  |  58 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CSqlDao"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9.  
  10. 'This function uses DAO to call SQL Server and get
  11. 'the contents of the input table name provided to
  12. 'the DAO table.  It returns a tabular array equivalent
  13. 'to the rowset returned from SQL Server.
  14.  
  15. Public Function DaoGetData(TableName As String, Token As Variant) As Variant
  16.     Dim aRecords As Variant
  17.     Dim dbDatabase As Database
  18.     Dim rs As Recordset
  19.     Dim sConnect As String
  20.     Dim sSQL As String
  21.     
  22.     'Create connection string to SQL Server
  23.     sConnect = "ODBC;DSN=pubs;DATABASE=pubs;UID=sa;PWD=;"
  24.     Set dbDatabase = Workspaces(0).OpenDatabase("", False, False, sConnect)
  25.     
  26.     'Bind the extended procedure to the client session
  27.     sSQL = "exec sp_bindsession '" + Token + "'"
  28.     dbDatabase.Execute sSQL, dbSQLPassThrough
  29.     
  30.     'Set the SQL statement to run
  31.     sSQL = "Select * from " + TableName
  32.     Set rs = dbDatabase.OpenRecordset(sSQL, Type:=dbOpenSnapshot)
  33.     
  34.     'Move to last record in order to count how many
  35.     'records are in the result set.
  36.     With rs
  37.         .MoveLast
  38.         .MoveFirst
  39.     End With
  40.     
  41.     'Get all the rows in the recordset and put them in a variant array
  42.     aRecords = rs.GetRows(rs.RecordCount)
  43.   
  44.     'Close resultset
  45.     rs.Close
  46.     
  47.     'Close db connection
  48.     dbDatabase.Close
  49.     
  50.     'Return the recordset to the caller in the form
  51.     'of a variant array
  52.     DaoGetData = aRecords
  53.    
  54. End Function
  55.  
  56.  
  57.  
  58.